package cn.base;

public class DeathLockClass implements Runnable {

    private String lock = "lock";
    private int count = 100;

    @Override
    public void run() {
        while (true) {
            count++;
            if (count % 2 == 0) {
                synchronized (lock) {
                    try {
                        lock.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    a();
                }
            } else {
                synchronized (this) {
                    try {
                        this.wait(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    b();
                }
            }
        }
    }

    private synchronized void a() {
        System.out.println("a function");
        this.notify();
    }

    private void b() {
        synchronized (lock) {
            System.out.println("b function");
            lock.notify();
        }
    }
}
